<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1 user-scalable=0"
    />
    <title>table方式居中</title>
    <style>
      html,
      body,
      section {
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
        position: relative;
      }

      a {
        color: #39c;
        text-decoration: none;
        display: inline-block;
      }

      header {
        top: 0;
        position: fixed;
        padding: 0.5rem 1rem;
        background: #def;
        width: 100%;
        display: block;
        z-index: 1;
      }

      header a {
        display: inline-block;
        padding: 0.5rem;
      }

      header a:hover {
        background: #39c;
        color: #fff;
      }

      .table {
        display: table;
        width: 100%;
      }

      .td {
        display: table-cell;
        vertical-align: middle;
        text-align: center;
      }

      .bgBlue {
        background: #def;
        padding: 1rem;
        width: 50%;
        margin: 0 auto;
      }
    </style>
  </head>
  <body>
    <header>
      <div>
        <a href="index.html">transform方式</a>
        <a href="margin.html">margin负值方式</a>
        <a href="margin-auto.html">margin-auto方式</a>
        <a href="table.html">display table方式</a>
        <a href="flex.html">flex方式</a>
      </div>
    </header>
    <section class="table">
      <div class="td">
        <div class="bgBlue">
          table方式垂直居中<br />
          兼容性：IE8+，以及其他几乎所有浏览器都支持（说几乎所有是因为firefox
          2不支持inline-table方式）
          <br />
          原理：父容器设为display:table,子容器设置为display:table-cell,然后设置vertical-align:
          middle;，设置text-align:center,
          <a
            href="https://github.com/cosyer/positionCenter/blob/master/table.html"
            >查看源代码</a
          >
        </div>
      </div>
    </section>
  </body>
</html>
